from selenium import webdriver
from selenium.webdriver.edge.options import Options
from selenium.webdriver.common.by import By
import time


# 设置浏览器、启动浏览器
def create_driver():
    options = Options()
    options.add_argument('--no-sandbox')
    options.add_experimental_option("detach", True)
    driver_edge = webdriver.Edge(options=options)
    return driver_edge
driver = create_driver()

driver.get("https://www.baidu.com/")
# 目的：结果验证
# 两种方式：文本验证； 截图
driver.find_element(By.ID, 'chat-textarea').send_keys('selenium')
driver.find_element(By.ID, 'chat-submit-button').click()
# time.sleep(3)
# 元素定位隐式等待（多少秒内找到元素就立刻执行，没有找到元素就报错）
driver.implicitly_wait(30)
el_list = driver.find_elements(By.XPATH, '//a')
for el in el_list:
    print(el.text)
    if 'selenium' in el.text:
        print("存在关键字")
    else:
        print("不合理的搜索结果")


